package Gui;

// from http://www.java-forums.org/awt-swing/6574-add-image-jframe.html
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class ImagePanel extends JPanel {
	private Image m_image;
	private boolean m_center;
	private Dimension size;

	public ImagePanel(Image image) {
		m_image = image;
		if (!m_center) {
			size = new Dimension(image.getWidth(null), image.getHeight(null));
		}
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
		setLayout(null);

	}

	public ImagePanel(String path, Dimension parentSize, boolean center)
			throws IOException {
		this(new ImageIcon(path).getImage());
		m_center = center;
		size = parentSize;
	}

	public ImagePanel(String path) throws IOException {
		// this(ImageIO.read(new File(path)));
		this(new ImageIcon(path).getImage());

	}

	public void paintComponent(Graphics g) {
		if (!m_center)
			g.drawImage(m_image, 0, 0, null);
		else
//			g.drawImage(m_image, getWidth() / 2 - m_image.getWidth(null),
//					getHeight() / 2 - m_image.getHeight(null), null);
			g.drawImage(m_image, 50,50, null);

	}
}
